#include "StdAfx.h"
#include "FPController.h"
#include "Enviroment.h"

using namespace Behavior;

Behavior::FPController::FPController( void ) :
target(0)
{

}

Behavior::FPController::~FPController( void )
{

}

MovingEffector* Behavior::FPController::GetTarget() const
{
	return target;
}

void Behavior::FPController::SetTarget( MovingEffector* val )
{
	target = val;
}

bool Behavior::FPController::Update( double timeElapsed )
{
	if(target==0 ||
		Enviroment::pMouseInputSensor==0 ||
		!Enviroment::pMouseInputSensor->IsButtonDown(MouseEnums::Right))
		return false;
	
	target->RotateVertical(-Enviroment::pMouseInputSensor->GetRelativeY());
	target->RotateHorizon(-Enviroment::pMouseInputSensor->GetRelativeX());

	if(Enviroment::pKeyboardInputSensor!=0)
	{
		if( Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_W)||
			Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_UP))
			target->MoveForward();

		if( Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_S)||
			Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_DOWN))
			target->MoveBack();

		if( Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_A)||
			Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_LEFT))
			target->ShiftLeft();

		if( Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_D)||
			Enviroment::pKeyboardInputSensor->IsKeyDown(KeyboardEnums::KC_RIGHT))
			target->ShiftRight();
	}

	return true;
}